package com.teamwork.module01.service.Impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teamwork.common.entity.module01.Classroom;
import com.teamwork.common.entity.module01.Paike;
import com.teamwork.common.entity.module01.dto.Kebiao;
import com.teamwork.common.result.Result;
import com.teamwork.module01.mapper.daomapper.KebiaoMapper;
import com.teamwork.module01.service.*;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class KebiaoServiceImpl extends ServiceImpl<KebiaoMapper, Kebiao> implements KebiaoService {

    @Resource
    private TeacherService teacherService;
    @Resource
    private ClassroomService classroomService;
    @Resource
    private ClassService classService;
    @Resource
    private CourseService courseService;

    @Override
    public Result page(int page, int size) {
        Page<Kebiao> kebiaoPage= new Page<>(page,size);
        this.page(kebiaoPage);
       return Result.success(kebiaoPage);


    }

    /**
     * 修改课表视图
     * @param paike
     * @return
     */
    @Override
    public boolean modify(Paike paike) {
        Integer classId = paike.getClassId();
        Integer courseId = paike.getCourseId();
        Integer teacherId = paike.getTeacherId();
        Integer classroomId = paike.getClassroomId();
        String className = classService.getById(classId).getClassName();
        String courseName = courseService.getById(courseId).getCourseName();
        String teacherName = teacherService.getById(teacherId).getTeacherName();
        Classroom classroom = classroomService.getById(classroomId);
        String buidingName = classroom.getBuidingName();
        Integer num = classroom.getNum();

      //  Integer id = paike.getId();
        Kebiao kebiao = this.getById(paike.getId());


        kebiao.setBuildingName(buidingName);
        kebiao.setClassName(className);
        kebiao.setTeacherName(teacherName);
        kebiao.setCourseName(courseName);
        kebiao.setNum(num);
        kebiao.setTerm(paike.getTerm());
        kebiao.setWeek(paike.getWeek());
        kebiao.setSingle(paike.getSingle());
        kebiao.setDay(paike.getDay());

        boolean b = this.updateById(kebiao);

        return b;
    }

    /**
     * 添加课表
     * @param paike
     * @return
     */
    @Override
    public boolean addOne(Paike paike) {
        Integer classId = paike.getClassId();
        Integer courseId = paike.getCourseId();
        Integer teacherId = paike.getTeacherId();
        Integer classroomId = paike.getClassroomId();
        String className = classService.getById(classId).getClassName();
        String courseName = courseService.getById(courseId).getCourseName();
        String teacherName = teacherService.getById(teacherId).getTeacherName();
        Classroom classroom = classroomService.getById(classroomId);
        String buidingName = classroom.getBuidingName();
        Integer num = classroom.getNum();

         Integer id = paike.getId();

         Kebiao kebiao =new Kebiao();
        kebiao.setId(id);
        kebiao.setBuildingName(buidingName);
        kebiao.setClassName(className);
        kebiao.setTeacherName(teacherName);
        kebiao.setCourseName(courseName);
        kebiao.setNum(num);
        kebiao.setTerm(paike.getTerm());
        kebiao.setWeek(paike.getWeek());
        kebiao.setSingle(paike.getSingle());
        kebiao.setDay(paike.getDay());

        boolean b = this.save(kebiao);

        return b;
    }
}
